package whf.file.wrapper;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import whf.file.entity.File;
import whf.framework.util.Base64;
import whf.framework.web.tag.TableColumn;
import whf.framework.web.tag.TableRow;
import whf.framework.web.tag.wrapper.IDisplayWrapper;

/**
 * @author wanghaifeng
 * @create Dec 29, 2006 5:31:14 PM
 * 
 */
public class SmallFileDisplayWrapper implements IDisplayWrapper {
	
	/* (non-Javadoc)
	 * @see whf.framework.web.tag.wrapper.IDisplayWrapper#writeBlockHtml(java.io.Writer, whf.framework.web.tag.TableRow)
	 */
	public void writeHtml(PageContext pageContext, List<TableColumn> displayColumns, TableRow row) throws JspException, IOException {
		HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
		Writer writer = pageContext.getOut();
		File file = (File)row.getRowObject();
		String sourceFile = file.getPhycialPath();
		
		String path = sourceFile;
		int li = path.lastIndexOf(".");
		String ext = path.substring(li + 1);
		path = path.substring(0, li)+".small."+ext;
		
		String sourceUrl = req.getContextPath() + "/Download?path="+Base64.encode(sourceFile);
		String url = req.getContextPath() + "/Download?path="+Base64.encode(path);

		writer.write("<a name='pic' href='"+sourceUrl+"' rel='lightbox[plants]'>");
		writer.write("<img src='"+url+"' border='0'>");
		writer.write("</a>");
		writer.write("<div align='left'>");
		writer.write(row.getRowObject().getDisplayName());
		writer.write("</div>");
		
	}

}
